package edu.hawaii.webspider;

import static org.junit.Assert.*;

import org.junit.Test;
/**
 * TotalLinksTest class tests the TotalLinks class.
 * @author kenglish
 *
 */
public class TestTotalLinks {
  TotalLinks totalLinks ;
  private static final String invalidUrl = "http://www.123sdf`1234asdfa1234sdaf''dsf.edu";
  private static final String noLinksUrl = "http://www.kenglish77.com/613/tests/nolinks.html";
  /**
   * Test the total links.
   *
   */
  @Test
  public void testTotalLinks() {
    String url = "http://www.hawaii.edu";
    totalLinks = new TotalLinks(url);    
    assertEquals("constructor should set start url ",totalLinks.getStartUrl(),url);
  }
  
  /**
   * Test the getLinks() method.
   */
  @Test  
  public void testGetLinks() {
    String url = "http://www.yahoo.com";
    totalLinks = new TotalLinks(url); 
    assertTrue("Should have more than one link for" + url ,totalLinks.getLinks(10) > 0);
  }  
  /**
   * Test getLinks() method, should fail.
   *
   */  
  @Test
  public void testGetLinksFail() {
    totalLinks = new TotalLinks(invalidUrl); 
    assertEquals("Should have no links for" + invalidUrl ,totalLinks.getLinks(2),0);
  }
  /**
   * Test getLinks() method with a page that has no links.
   *
   */    
  @Test
  public void testGetLinksNoLinks() {
    totalLinks = new TotalLinks(noLinksUrl); 
    assertEquals("Should have no links for" + noLinksUrl ,totalLinks.getLinks(10),0);
  }
  /**
   * Test getLinks(), also calls main to ensure we get full coverage. 
   *  
   */
  @Test
  public void testGetLinksNoLinksandMain() {
    totalLinks = new TotalLinks(noLinksUrl); 
    assertEquals("Should have no links for" + noLinksUrl ,totalLinks.getLinks(10),0);
    TotalLinks.main(new String[1]);
  }
  
  

}
